<template>
  <div>
    <!-- 功能按钮 -->
    <el-form class="tableSearch" size="mini">
      <el-form-item>
        <el-button type="primary" @click="goBack()">返回</el-button>
        <el-button type="primary" v-show="see || !disabled" @click="submitForm('formdata')">保存</el-button>
        <el-button type="primary" v-show="see || !disabled" @click="handleGet()">取来源单</el-button>
        <el-button type="primary" v-if="setRole('发货')" v-show="canEdit" @click="handlePostDan()">已发货</el-button>
      </el-form-item>
    </el-form>

    <el-form :model="formdata" :rules="rules" ref="formdata" label-width="120px" size="mini">
      <el-row>
        <el-col :span="8">
          <el-form-item label="供应商：">
            <el-input v-model="formdata.supplierName" disabled placeholder="请取来源单获取供应商"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="来源单号：">
            <el-input v-model="formdata.fromCode" disabled placeholder="请取来源单获取来源单号"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="订单状态：">
            <el-input v-model="saleStatusArray[formdata.purchaseStatus]" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="退货日期：" prop="returnDate">
            <el-date-picker :disabled="disabled" v-model="formdata.returnDate" type="date" placeholder="选择退货日期" format="yyyy年 MM 月 dd 日" value-format="yyyy-MM-dd"></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="单据号：" prop="purchaseinCode">
            <el-input v-model="formdata.purchaseinCode" disabled placeholder="单据编号自动生成"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="单据日期：">
            <el-date-picker v-model="formdata.orderDate" format="yyyy年 MM 月 dd 日" value-format="yyyy-MM-dd" type="date" disabled></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="!disabled">
        <el-col :span="8">
          <el-form-item label="收货人：" prop="consignee">
            <el-select v-model="contactData.id" @change="selectContact">
              <el-option v-for="(item, index) in contactList" :key="index" :label="item.consignee" :value="item.id"></el-option>
            </el-select>
            <el-button type="text" @click="editContact()" size="mini">修改</el-button>
            <el-button type="text" @click="delContact()" size="mini">删除</el-button>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="">
            <el-button type="primary" @click="clickAddContact()" size="mini">添加收货人</el-button>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="disabled">
        <el-col :span="8">
          <el-form-item label="收货人：">
            <el-input v-model="formdata.consignee" disabled></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="手机号码：">
            <span>{{contactData.linkman}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="座机电话：">
            <span>{{contactData.fixPhone}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="地址：">
            <span>{{contactData.detailAddress}}</span>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="canEdit">
        <el-col :span="8">
          <el-form-item label="物流单号：" maxlength="50">
            <!-- :disabled="disabled" -->
            <el-input v-model="formdata.logisticsCode"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <!-- 表格 -->
    <div class="tableMain">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column type="index" align="center"></el-table-column>
        <el-table-column prop="goodsCode" label="商品货号" align="center"></el-table-column>
        <el-table-column prop="barCode" label="商品条码" align="center"></el-table-column>
        <el-table-column prop="goodsName" label="商品" align="center"></el-table-column>
        <el-table-column prop="goodsBatchNumber" label="商品批次" align="center">
          <template slot-scope="scope">
          <span v-if="scope.row.isBatch == '1'">{{scope.row.goodsBatchNumber}}</span>
          <span v-if="scope.row.isBatch == '0'">{{"---"}}</span>
        </template>
        </el-table-column>
        <!-- 集团订单新加功能5/31 -->
        <el-table-column prop="dateInProduced" label="生产日期" align="center">
          <template slot-scope="scope">
          <span v-if="scope.row.isBatch == '1'">{{scope.row.dateInProduced}}</span>
          <span v-if="scope.row.isBatch == '0'">{{"---"}}</span>
        </template>
        </el-table-column>
        <el-table-column prop="warehouseName" label="仓库" align="center"></el-table-column>
        <el-table-column prop="goodsSpec" label="商品规格" align="center">
          <template slot-scope="scope">
            <div v-for="(item, index) in scope.row.goodsSpec" :key="index">
              <span>{{item.paramName}} :</span>
              <span>{{item.paramValue}} </span>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="unitName" label="单位" align="center"></el-table-column>
        <el-table-column prop="goodsPrice" label="销售价" align="center"></el-table-column>
        <el-table-column prop="returnNum" label="数量" align="center" width="150">
          <template slot-scope="scope">
            <el-input v-if="!disabled" v-model="scope.row.returnNum" size="mini" type="text" style="width:100px" oninput="if(value.length>8)value=value.slice(0,8)" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'')}else{this.value=this.value.replace(/\D/g,'')}" onafterpaste="if(this.value.length==1){this.value=this.value.replace(/[^1-9]/g,'0')}else{this.value=this.value.replace(/\D/g,'')}"></el-input>
            <span v-else>{{scope.row.returnNum}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="goodsAmount" label="总价" align="center">
          <template slot-scope="scope">
            <span>{{(Number(scope.row.goodsPrice)*Number(scope.row.returnNum)).toFixed(2)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" v-if="!disabled">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.$index)" type="text" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    
    <div class="th-right">
      <el-form :model="formdata" ref="formdata" label-width="120px" size="mini">
        <el-row>
          <el-col :span="10">&nbsp;</el-col>
          <el-col :span="6">
            <el-form-item label="操作员：">
              <el-input v-model="formdata.creator" disabled></el-input>
            </el-form-item>
            <el-form-item label="备注：">
              <el-input v-model="formdata.remark" type="textarea" :disabled="disabled"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="总计：" prop="priceTotal">
              <el-input v-model="formdataTotal" disabled></el-input>
            </el-form-item>
            <el-form-item label="运费：" prop="freight">
              <sd-input v-if="operation!='2'" :val.sync="formdata.freight"></sd-input>
              <el-input v-if="operation=='2'" v-model="formdata.freight" :disabled="disabled"></el-input>
            </el-form-item>
            <el-form-item label="应退总金额：">
              <el-input v-model="formdataAllTotal" disabled></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>

    <!-- 取来源单弹出框 -->
    <el-dialog title="来源单选择" :visible.sync="dialogGet" :closeOnClickModal="false" :closeOnPressEscape="false">
      <el-form label-width="0" size="mini">
        <el-form-item>
          <el-button type="primary" @click="save_cai()">选择</el-button>
          <el-button @click="dialogGet=false">取消</el-button>
        </el-form-item>
      </el-form>
      <el-form size="mini">
        <el-form-item label="" label-width="0">
          <el-input v-model="selectData.keyGet" placeholder="输入单据号" style="width:200px;"></el-input>
          <el-button type="primary" @click="handleSearchGet">搜索</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="getArray" tooltip-effect="dark" highlight-current-row @current-change="handleChangeGet">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column prop="inCode" label="单据编号" align="center"></el-table-column>
        <el-table-column prop="orderDate" label="日期" align="center" :formatter="tim"></el-table-column>
        <el-table-column prop="shopName" label="供应商" align="center"></el-table-column>
      </el-table>
      <page-unit :pageData="pageDataGet" :func="_getRepertoryInBoundListPage"></page-unit>
    </el-dialog>

    <!-- 联系人弹窗 -->
    <el-dialog title="联系人" class="addshopname" :visible.sync="dialogContact" :closeOnClickModal='false' :closeOnPressEscape='false' width="35%">
      <i class="el-icon-close icon" @click="dialogContact=false"></i>
      <el-form :model="contactDialogForm" :rules="rulesContact" ref="contactDialogForm" size="mini" label-width="100px">
        <el-form-item label="收货人：" prop="consignee">
          <el-input v-model="contactDialogForm.consignee" maxlength="50"></el-input>
        </el-form-item>
        <el-form-item label="手机号码：" prop="linkman">
          <el-input v-model="contactDialogForm.linkman" maxlength="11" @keyup.native='replace(contactDialogForm.linkman, contactDialogForm, "linkman")'></el-input>
        </el-form-item>
        <el-form-item label="座机号码：">
          <el-input v-model="contactDialogForm.fixPhone" maxlength="12" @keyup.native='replace(contactDialogForm.fixPhone, contactDialogForm, "fixPhone")'></el-input>
        </el-form-item>
        <el-form-item label="地址：" prop="area">
          <v-distpicker @selected="onSelected" :province="contactDialogForm.province" :city="contactDialogForm.city" :area="contactDialogForm.area"></v-distpicker>
        </el-form-item>
        <el-form-item label="" prop="address">
          <el-input v-model="contactDialogForm.address" placeholder="详细地址(必填)" maxlength="200"></el-input>
        </el-form-item>
        <el-form-item label="设为默认地址">
          <el-switch v-model="contactDialogForm.isDefault" inactive-color="red" active-value="0" inactive-value="1"></el-switch>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSaveContact('contactDialogForm')">保存</el-button>
          <el-button @click="dialogContact=false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from "vuex";
import util from "@/util";
import state from "@/util/state"
import SdInput from "components/SdInput";
import pageUnit from "components/Page";
import VDistpicker from "v-distpicker";
import {
  selectOrderGoodsPurchaseReturnDetail,
  insertOrderGoodsPurchaseReturn,
  getRepertoryInBoundListPage,
  getRepertoryInBoundDetail,
  getDeliveryAddressList,
  updateDeliveryAddress,
  saveDeliveryAddress,
  deliverReturnGoods
} from "@/api";

export default {
  components: { SdInput, pageUnit, VDistpicker },

  data () {
    return {
      disabled: false,  // 不可点击
      canEdit: false,
      id: "",  // 查看时传入id值
      formdata: {
        id: '',
        supplierId: "",  // 供应商id
        supplierName: "",  // 供应商名称
        fromCode: "",  // 来源单号
        purchaseStatus: 0,  // 单据状态
        returnDate: "",  // 退货日期
        orderDate: "",  // 单据日期
        logisticsCode: "",  // 物流单号
        consignee: "",
        creator: "",  // 操作员
        remark: "",  // 备注
        returnAmount: 0,  // 总计
        freight: 0,  // 运费
        amount: 0,  // 应退总金额
      },
      contactData: {
        id: '',  // 选中的收货人Id
        consignee: '',  // 收货人
        fixPhone: '',  // 收货人座机号
        linkman: '',  // 收货人手机
        countries: '中国',
        province: '',  // 收货人省
        city: '',  // 收货人市
        area: '',  // 收货人区
        address: '',  // 收货人地址
        detailAddress: '',  // 收货人详细地址
        isDefault: '1',  // 是否默认
      },
      contactDialogForm: {
        id: '',
        consignee: '',
        fixPhone: '',
        linkman: '',
        countries: '中国',
        province: '',
        city: '',
        area: '',
        address: '',
        isDefault: '1'
      },  // 联系人弹窗表单
      dialogContact: false,  // 联系人弹窗
      contactList: [],  // 收货人数组
      saleStatusArray: state.returnStatusArr,
      see: true,  // 查看时不可见
      rules: {
        returnDate: [{ type: 'string', required: true, message: "请选择退货时间", trigger: "change" }],
        consignee: [{ required: true, message: "请选择收货人" }],
      },
      rulesContact: {
        consignee: [{ required: true, message: "请输入收货人", trigger: "blur" }],
        linkman: [
          { required: true, message: "请输入手机号码", trigger: "blur" },
          { validator: util.validMobilePhoneCallback, trigger: 'blur' }
        ],
        area: [{ required: true, message: "请选择地址", trigger: "blur" }],
        address: [{ required: true, message: "请输入地址信息", trigger: "blur" }]
      },
      tableData: [],  // 商品列表
      selectData: {
        keyGet: ''
      },
      dialogGet: false,  // 取来源单弹窗
      getArray: [],  // 取来源单数组
      selectionGet: [],  // 选择的来源单数组对象
      pageDataGet: {
        pageSize: 20,
        currentPage: 1,
        totalItems: 0,
        pageSizeArr: [5, 10, 20]
      },
    };
  },

  created () {
    this.operation = util.getQuery().operation;  // 新增1，查看2
    this.id = util.getQuery().id;  // 查看id
  },

  computed: {
    ...mapState({
      merchantId: state => state.merchantId,
      userInfo: state => state.userInfo,
      path: state => state.path,
      linkName: state => state.linkName,
      mobile: state => state.mobile,
      companyName: state => state.companyName,
      userId: state => state.userId,
      power: state => state.power,
    }),

    formdataTotal: function () {
      let totalPrice = 0;
      this.tableData.forEach(item => {
        item.goodsAmount = Number(item.goodsPrice) * Number(item.returnNum);
        totalPrice += item.goodsAmount
      })
      this.formdata.returnAmount = Number(totalPrice).toFixed(2);
      return isNaN(totalPrice) ? 0 : Number(totalPrice).toFixed(2);
    },

    formdataAllTotal: function () {
      let totalPrice = 0;
      this.tableData.forEach(item => {
        item.goodsAmount = Number(item.goodsPrice) * Number(item.returnNum);
        totalPrice += item.goodsAmount
      })
      this.formdata.amount = (Number(totalPrice) + Number(this.formdata.freight)).toFixed(2);
      return this.formdata.amount
    }
  },

  mounted () {
    // 查看，保存按钮和取来源单按钮不可见， 某些输入框不可点击
    if (util.getQuery().operation == 2) {
      this.see = false;
      this.disabled = true
      this.getDetails();
    } else {
      this.init();  // 初始化
    }
  },
  
  methods: {
    // 权限配置
    setRole (key) {
      return util.selectTitle(this.power, key);
    },
    // 初始化
    init () {
      this.formdata.creator = this.companyName
      this.formdata.orderDate = util.getNowFormatDate()
    },
    tim (row) {
      return util.foryear(parseInt(row.orderDate));
    },
    replace (value, obj, key) {
      let res = ''
      switch (key) {
        case 'linkman':
          res = util.replaceNumber(value);
          break;
        case "fixPhone":
          res = util.replaceFixPhone(value);
          break;
        default:
          break;
      }
      this.$set(obj, key, res);
    },
    goBack () {
      history.back();
    },
    submitForm (formName) {
      if (this.contactData.id !== '') {
        this.formdata.consignee = this.contactData.consignee
      } else {
        this.$message.error('请先选择收货人')
        return false
      }
      if (this.tableData.length == 0) {
        this.$message.error("商品不能为空！")
        return false;
      }
      if (this.formdata.returnDate == "") {
        this.$message.error("退货日期不能为空！")
        return false;
      }
      for (let i = 0; i < this.tableData.length; i++) {
        if (this.tableData[i].returnNum == 0) {
          this.$message({
            type: "error",
            message: "商品数量不能为0"
          });
          return false;
        } else {
          this.tableData[i].goodsNum = this.tableData[i].returnNum
        }
      }

      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.handleSave();
        } else {
          return false;
        }
      });
    },
    // 新增保存
    handleSave () {
      this.tableData.forEach(item=>{
        item.goodsDetailId=item.id
      })
      insertOrderGoodsPurchaseReturn({
        supplierName: this.formdata.supplierName,
        returnDate: this.formdata.returnDate,
        orderDate: this.formdata.orderDate,
        shopId: this.merchantId,
        creator: this.userId,
        returnAmount: this.formdata.returnAmount,
        freight: this.formdata.freight,
        purchaseId: this.formdata.id,
        amount: this.formdata.amount,
        purchaseType: 1,
        remark: this.formdata.remark,
        goodsList: JSON.stringify(this.tableData),
        shopName: this.companyName,
        customerId: this.formdata.supplierId,
        customerName: this.formdata.supplierName,
        consignee: this.contactData.consignee,
        linkman: this.contactData.linkman,
        fixPhone: this.contactData.fixPhone,
        address: this.contactData.address,
        countries: this.contactData.countries,
        province: this.contactData.province,
        city: this.contactData.city,
        area: this.contactData.area,
        deliveryAddressList: JSON.stringify(this.contactList)
      }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.msg)
          history.back()
        }
      });
    },
    //表格删除
    handleClick (index) {
      this.tableData.splice(index, 1);
    },
    handlePostDan () {
      deliverReturnGoods({
        id: this.formdata.id,
        logisticsCode: this.formdata.logisticsCode
      }).then(res => {
        if (res.code == 200) {
          this.$message.success(res.msg)
          history.back()
        }
      })
    },
    //取来源单
    handleGet () {
      this._getRepertoryInBoundListPage(this.pageDataGet.pageSize, 1);
      this.dialogGet = true;
    },
    // 点击确定取来源单
    save_cai () {
      getRepertoryInBoundDetail({
        id: this.selectionGet.id,
        arriveNum: "1"
      }).then(res => {
        if (res.data !== null) {
          this.formdata.supplierName = res.data.shopName;
          this.formdata.fromCode = res.data.inCode;
          res.data.goodsList.forEach(i => {
            i.minNum = i.returnNum
          })
          this.tableData = res.data.goodsList;
          this.formdata.freight = 0;
          this.formdata.id = res.data.id;
          this.formdata.supplierId = res.data.shopId;
          this.formdata.remark = "";
          this.formdata.creator = res.data.userName;
          this.dialogGet = false;
          this.getContactList()
        }
      });
    },
    // 单选取来源单
    handleChangeGet (val) {
      if (val) {
        this.selectionGet = val;
      } else {
        this.selectionGet = [];
      }
    },

    // 取来源单列表
    _getRepertoryInBoundListPage (pageSize, pageNum) {
      getRepertoryInBoundListPage({
        shopId: this.merchantId,
        pageSize: pageSize,
        pageNum: pageNum,
        inType: 1,
        inStatus: 0,
        inCode: this.selectData.keyGet,
        arriveNum: 1
      }).then(res => {
        this.pageDataGet.totalItems = res.data.pageTotal;
        this.getArray = res.data.list;
      });
    },
    // 取来源单搜索
    handleSearchGet () {
      this._getRepertoryInBoundListPage(20, 1);
    },
    // 查看退货出库单详情
    getDetails () {
      let data = {
        id: this.id
      };
      selectOrderGoodsPurchaseReturnDetail(data).then(res => {
        this.formdata = res.data
        this.formdata.creator = res.data.userName
        this.formdata.returnDate = util.foryear(parseInt(res.data.returnDate));  // 退货日期
        this.formdata.orderDate = util.foryear(parseInt(res.data.orderDate));  // 单据日期
        this.tableData = res.data.goodsList;  // 商品列表
        this.contactData.consignee = res.data.consignee
        this.contactData.fixPhone = res.data.fixPhone
        this.contactData.linkman = res.data.linkman
        this.contactData.countries = res.data.countries
        this.contactData.province = res.data.province
        this.contactData.city = res.data.city
        this.contactData.area = res.data.area
        this.contactData.address = res.data.address
        this.contactData.detailAddress = res.data.address
        this.contactData.isDefault = res.data.isDefault
        if (this.formdata.purchaseStatus == '2') {  // 待发货状态
          this.canEdit = true
        }
      });
    },
    // 点击修改收货人
    editContact () {
      if (this.contactData.id !== '') {
        let resData = this.contactList.filter(item => {
          return item.id === this.contactData.id
        })
        this.contactDialogForm = JSON.parse(JSON.stringify(resData[0]))
        this.$set(this.contactDialogForm, 'isDefault', resData[0].isDefault.toString())
        this.dialogContact = true
      }
    },
    // 点击删除收货人
    delContact () {
      if (this.contactData.id !== '') {
        this.$confirm("确定要删除当前收货人吗?", "提示", {
          center: true,
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          closeOnClickModal: false,
          closeOnPressEscape: false
        }).then(() => {
          let data = {
            id: this.contactData.id,
            dl: 1
          };
          updateDeliveryAddress(data).then(res => {
            if (res.code == 200) {
              this.$message.success(res.msg)
              this.getContactList()
            }
          });
        }).catch(() => { })
      }
    },
    // 点击添加收货人
    clickAddContact () {
      if (this.selectionGet.id) {
        Object.keys(this.contactDialogForm).forEach(key => {
          this.contactDialogForm[key] = ''
        })
        this.$set(this.contactDialogForm, 'isDefault', '1')
        this.dialogContact = true
      } else {
        this.$message.error('请先取来源单！')
      }
    },
    // 获取收货人列表
    getContactList () {
      getDeliveryAddressList({
        shopId: this.merchantId,
        customerId: this.formdata.supplierId
      }).then(res => {
        if (res.code == 200) {
          this.contactList = res.data.list
          this.contactList.forEach(item => {
            item.detailAddress = item.province + item.city + item.area + item.address
          })
          if (this.contactList.length !== 0) {
            let defaultCon = this.contactList.filter(item => {
              return Number(item.isDefault) === 0
            })
            if (defaultCon.length === 1) {  // 选择默认地址
              this.contactData = JSON.parse(JSON.stringify(defaultCon[0]))
              this.formdata.consignee = this.contactData.consignee
            } else {  // 无默认地址，取最新一条
              let len = this.contactList.length
              this.contactData = JSON.parse(JSON.stringify(this.contactList[len - 1]))
              this.formdata.consignee = this.contactData.consignee
            }
          } else {
            // 可能是删除完数据，所以要清除缓存数据
            Object.keys(this.contactData).forEach(key => {
              this.contactData[key] = ''
            })
            this.contactData.isDefault = '1'
          }
        }
      })
    },
    // 选择收货人
    selectContact (val) {
      if (val) {
        let data = this.contactList.filter(item => {
          return item.id === val
        })
        this.contactData = JSON.parse(JSON.stringify(data[0]))
        this.formdata.consignee = this.contactData.consignee
      }
    },
    // 地址联动选择
    onSelected (val) {
      this.contactDialogForm.province = val.province.value;
      this.contactDialogForm.city = val.city.value;
      this.contactDialogForm.area = val.area.value;
    },
    // 收货人弹窗点击确定，新增或修改收货联系人
    handleSaveContact (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if (this.contactDialogForm.id !== '') { // 修改
            updateDeliveryAddress({
              id: this.contactData.id,
              consignee: this.contactDialogForm.consignee,
              linkman: this.contactDialogForm.linkman,
              fixPhone: this.contactDialogForm.fixPhone,
              countries: this.contactDialogForm.countries,
              province: this.contactDialogForm.province,
              city: this.contactDialogForm.city,
              area: this.contactDialogForm.area,
              address: this.contactDialogForm.address,
              isDefault: this.contactDialogForm.isDefault,
              dl: 0
            }).then(res => {
              if (res.code == 200) {
                this.getContactList()
                this.dialogContact = false
              }
            })
          } else {
            if (this.contactList.length === 50) {
              this.$message.error('收货人最多50条！')
              return false;
            }
            saveDeliveryAddress({
              shopId: this.merchantId,
              customerId: this.formdata.supplierId,
              consignee: this.contactDialogForm.consignee,
              linkman: this.contactDialogForm.linkman,
              fixPhone: this.contactDialogForm.fixPhone,
              countries: this.contactDialogForm.countries,
              province: this.contactDialogForm.province,
              city: this.contactDialogForm.city,
              area: this.contactDialogForm.area,
              address: this.contactDialogForm.address,
              isDefault: this.contactDialogForm.isDefault
            }).then(res => {
              if (res.code == 200) {
                this.getContactList()
                this.dialogContact = false
              }
            })
          }
        } else {
          return false;
        }
      });
    },
  }
};
</script>
<style>
.distpicker-address-wrapper select {
  height: 32px;
  font-size: 13px;
  padding: 0 0.75rem;
}
</style>
<style scoped>
.th-right {
  margin-top: 20px;
}
</style>
